<?php

//封装对数据库进行的操作
class sql_server {
 
    private $mysqli;
    private $host = "localhost:3306";
    private $user = "root";
    private $password = "1589";
    private $db = "message";
    
    //调用数据库时自动执行
    function __construct() {
     $host = "localhost:3306";
     $user = "root";
     $password = "1589";
     $db = "message";
    	$conn = new mysqli($host, $user, $password);
 
		// 检测连接
		if ($conn->connect_error) {
    		die("连接失败: " . $conn->connect_error);
			} 
//			echo "连接成功";
        $this->mysqli = new mysqli($this->host, $this->user, $this->password, $this->db);
        if ($this->mysqli->connect_error) {
            die("连接失败" . $this->mysqli->conecct_error);
        }
    }
 
//设置编码
    function set_character() {
        $this->mysqli->query("set names utf8");
    }
 
//执行sql语句
    function execute_dql($sql) {
        $res = $this->mysqli->query($sql) or
                die("操作失败" . $this->mysqli->error);
        return $res;
    }
    
    
//关闭连接
    function close_connect() {
        if (!empty($this->mysqli)) {
            $this->mysqli->close();
        }
    }
 

}
